package com.rtos.vo.dat;

import com.rtos.model.device.Device;
import com.rtos.model.process.Process;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: biubiu0002
 * @Date: 2021-10-26 16:35
 * 封装给javafx展示
 **/
@Data
@AllArgsConstructor
public class DeviceAllocationTableVO {
    public StringProperty deviceName;
    public StringProperty pid;
//    public StringProperty waitingProcess;
    public StringProperty waitingProcess;


    public StringProperty deviceNameProperty(){return this.deviceName;}
    public StringProperty pidProperty(){return this.pid;}
    public StringProperty waitingProcessProperty(){return this.waitingProcess;}

    public static ObservableList<DeviceAllocationTableVO> datList = FXCollections.observableArrayList();

    public static DeviceAllocationTableVO a1 = new DeviceAllocationTableVO(new SimpleStringProperty("A1"), Device.getInstance().a1Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO a2 = new DeviceAllocationTableVO(new SimpleStringProperty("A2"), Device.getInstance().a2Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO b1 = new DeviceAllocationTableVO(new SimpleStringProperty("B1"), Device.getInstance().b1Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO b2 = new DeviceAllocationTableVO(new SimpleStringProperty("B2"), Device.getInstance().b2Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO b3 = new DeviceAllocationTableVO(new SimpleStringProperty("B3"), Device.getInstance().b3Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO c1 = new DeviceAllocationTableVO(new SimpleStringProperty("C1"), Device.getInstance().c1Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO c2 = new DeviceAllocationTableVO(new SimpleStringProperty("C2"), Device.getInstance().c2Property(), new SimpleStringProperty());
    public static DeviceAllocationTableVO c3 = new DeviceAllocationTableVO(new SimpleStringProperty("C3"), Device.getInstance().c3Property(), new SimpleStringProperty());


    public DeviceAllocationTableVO(SimpleStringProperty deviceNameProperty, SimpleStringProperty pidProperty, StringProperty waitingProcess) {
        this.deviceName=deviceNameProperty;
        this.pid=pidProperty;
        this.waitingProcess=waitingProcess;
    }



    public static void setDATTableView(TableView<DeviceAllocationTableVO> tableView,
                                       TableColumn<DeviceAllocationTableVO, StringProperty> deviceName,
                                       TableColumn<DeviceAllocationTableVO, StringProperty> pid,
                                       TableColumn<DeviceAllocationTableVO, StringProperty> waitingProcess
    ) {


        datList.add(a1);
        datList.add(a2);
        datList.add(b1);
        datList.add(b2);
        datList.add(b3);
        datList.add(c1);
        datList.add(c2);
        datList.add(c3);

        deviceName.setCellValueFactory(new PropertyValueFactory("deviceName"));
        pid.setCellValueFactory(new PropertyValueFactory("pid"));
        waitingProcess.setCellValueFactory(new PropertyValueFactory("waitingProcess"));
        tableView.setItems(datList);


    }


}
